<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page import="java.util.*"%>

<%@ page isELIgnored="false"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>订单管理系统主页</title>
	<script src="http://code.jquery.com/jquery-1.4.1.min.js"></script>
	<script>
	function showInsert() {
		document.getElementById("insert").style.display = "block";				
	}	
	function updateDin(id, name, adderss, date){
		document.getElementById("update").style.display = "block";
		document.getElementById("id").value=id;
		document.getElementById("id").style.backgroundColor = "#EEE8CD";
        document.getElementById("name").value=name;
        document.getElementById("address").value=adderss;
        document.getElementById("date").value=date;
	}
    //删除订单
    function delete_din(commodityId){
        if(confirm("确认要「删除」这篇文章吗？"))
            $.ajax({
                type: "GET",
                url: "deleteDin",
                data: "commodityId=" + commodityId,
                dataType: 'text',
                success: function(message){
                    alert(message);
                    $("#dins").find("tr[id='"+commodityId+"']").remove();
                }
            });
    }
</script>
<style>
	body {
		text-align: center
	}
</style>
</head>

<body>


	<h2>
		管理者 ${manager } ,欢迎使用订单管理系统 , 注销请点击<a href="logout">注销</a>
	</h2>
	<%
		String message = request.getParameter("message");
		request.setAttribute("message", message);
	%>
	${message}
	<div class="container" style="margin-left: auto; margin-right: auto;">
		<table id="dins" width="400" border="1" cellspacing="0" align="center">
			<tr>
				<th>订单id</th>
				<th>订单名</th>
				<th>订单位置</th>
				<th>订单时间</th>
				<th colspan="2">操作</th>
			</tr>
			<c:forEach items="${all}" var="a">
				<tr id="${a.commodityId}">
					<td>${a.commodityId}</td>
					<td>${ a.commodityName}</td>
					<td>${ a.commodityAddress}</td>
					<td>${ a.commodityDate}</td>
					<td>
						<button type="button" onClick='updateDin(${a.commodityId},
								"${a.commodityName}", "${a.commodityAddress}", "${a.commodityDate}")'>
							更新
						</button>
					</td>
					<td>
						<button type="button" onclick='delete_din("${a.commodityId}")'>删除</button>
					</td>
				</tr>
			</c:forEach>
		</table>
		<button type="button" onClick="showInsert()">增加订单</button>
		<br />

		<div id="update" style="display: none;">
			<h2>-------------更改订单------------</h2>
			<form action="updateDin" method="post">
				<table width="250" border="1" cellspacing="0"   align="center">
					<tr>
						<td>商品id:</td>
						<td><input type="text" name="commodityId" id="id"
							readonly="readonly"></td>
					</tr>
					<tr>
						<td>商品名</td>
						<td><input type="text" name="commodityName" id="name"/></td>
					</tr>
					<tr>
						<td>商品地址:</td>
						<td><input type="text" name="commodityAddress" id="address"/></td>
					</tr>
					<tr>
						<td>购买时间:</td>
						<td><input type="text" name="commodityDate" id="date"/></td>
						<tr>
							<tr>
								<td colspan="2" align="center" valign="middle"><input
									type="submit" value="更改" /></td>
							</tr>
				</table>
			</form>
		</div>

		<div id="insert" style="display: none;">
			<h2>-------------添加订单------------</h2>
			<form action="insertDin" method="post">
				<table width="250" border="1" cellspacing="0"   align="center">
					<tr>
						<td>商品id:</td>
						<td><input type="text" name="commodityId"></td>
					</tr>
					<tr>
						<td>商品名:</td>
						<td><input type="text" name="commodityName" /></td>
					</tr>
					<tr>
						<td>商品地址:</td>
						<td><input type="text" name="commodityAddress" /></td>
					</tr>
					<tr>
						<td>购买时间:</td>
						<td><input type="text" name="commodityDate" /></td>
						<tr>
							<tr>
								<td colspan="2" align="center" valign="middle"><input
									type="submit" value="提交" /></td>
							</tr>
				</table>
			</form>
		</div>
	</div>
</body>
</html>